<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css">


  <meta name="keywords" content="intellij idea,插件,android-studio,plugin,">








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2">






<meta name="description" content="简介本篇博客主要是介绍 Intellij Idea插件的基础环境的搭建，以及简单的入门操作，用于熟悉插件的编写流程，更快的熟悉和适应插件的编写。如有错误，请在留言中指正，谢谢。  系列汇总地址   基础知识环境搭建首先为了方便开发，我们采用 Intellij Idea 作为我们开发的IDE,  可以点此下载  。安装过程比较简单我就不在此赘述了，下面我们讲解下如何设置，让你能够搭建好可以运行的插件">
<meta name="keywords" content="intellij idea,插件,android-studio,plugin">
<meta property="og:type" content="article">
<meta property="og:title" content="【Intellij Idea 插件从入门到深坑】基础的AnAction">
<meta property="og:url" content="http://guohaiyang.tk/post/1f02658.html">
<meta property="og:site_name" content="Android探索之路">
<meta property="og:description" content="简介本篇博客主要是介绍 Intellij Idea插件的基础环境的搭建，以及简单的入门操作，用于熟悉插件的编写流程，更快的熟悉和适应插件的编写。如有错误，请在留言中指正，谢谢。  系列汇总地址   基础知识环境搭建首先为了方便开发，我们采用 Intellij Idea 作为我们开发的IDE,  可以点此下载  。安装过程比较简单我就不在此赘述了，下面我们讲解下如何设置，让你能够搭建好可以运行的插件">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-18%20%E4%B8%8B%E5%8D%8811.58.59.png">
<meta property="og:image" content="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8A%E5%8D%8812.08.24.png">
<meta property="og:image" content="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8A%E5%8D%8812.29.13.png">
<meta property="og:image" content="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8B%E5%8D%8811.16.32.png">
<meta property="og:image" content="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8B%E5%8D%8811.22.28.png">
<meta property="og:image" content="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8B%E5%8D%8811.24.23.png">
<meta property="og:updated_time" content="2017-12-26T17:44:13.284Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【Intellij Idea 插件从入门到深坑】基础的AnAction">
<meta name="twitter:description" content="简介本篇博客主要是介绍 Intellij Idea插件的基础环境的搭建，以及简单的入门操作，用于熟悉插件的编写流程，更快的熟悉和适应插件的编写。如有错误，请在留言中指正，谢谢。  系列汇总地址   基础知识环境搭建首先为了方便开发，我们采用 Intellij Idea 作为我们开发的IDE,  可以点此下载  。安装过程比较简单我就不在此赘述了，下面我们讲解下如何设置，让你能够搭建好可以运行的插件">
<meta name="twitter:image" content="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-18%20%E4%B8%8B%E5%8D%8811.58.59.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"hide","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"输入关键词进行搜索","hits_empty":"找不到有关『${query}』的文章，是不是去火星了？","hits_stats":"呼哧呼哧~~ 总于找到${hits} 篇文章，花了 ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://guohaiyang.tk/post/1f02658.html">





  <title>【Intellij Idea 插件从入门到深坑】基础的AnAction | Android探索之路</title>
  














</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <!-- 添加github fork me -->
    <a href="https://github.com/guohaiyang1992" rel="external nofollow noopener noreferrer" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Android探索之路</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">吾将上下而求索</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br>
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://guohaiyang.tk/post/1f02658.html">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="guohaiyang">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="http://avatar.csdn.net/E/A/A/1_guohaiyang1992.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Android探索之路">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">【Intellij Idea 插件从入门到深坑】基础的AnAction</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-20T00:21:00+08:00">
                2017-12-20
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/Intellij/" itemprop="url" rel="index">
                    <span itemprop="name">Intellij</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/post/1f02658.html" class="leancloud_visitors" data-flag-title="【Intellij Idea 插件从入门到深坑】基础的AnAction">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读热度</span>
               
                 <span class="leancloud-visitors-count"></span> ℃
             </span>
          

          

          
            <br>
            <div class="post-wordcount">
              
                <!--
                  <span class="post-meta-divider">|</span>
                -->
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,357 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  5 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a><strong>简介</strong></h2><p>本篇博客主要是介绍 <code>Intellij Idea</code><br>插件的基础环境的搭建，以及简单的入门操作，用于熟悉插件的编写流程，更快的熟悉和适应插件的编写。如有错误，请在留言中指正，谢谢。 <a href="http://blog.csdn.net/guohaiyang1992/article/details/78838307" rel="external nofollow noopener noreferrer" target="_blank"> 系列汇总地址
</a></p>
<hr>
<h2 id="基础知识"><a href="#基础知识" class="headerlink" title="基础知识"></a><strong>基础知识</strong></h2><h3 id="环境搭建"><a href="#环境搭建" class="headerlink" title="环境搭建"></a><strong>环境搭建</strong></h3><p>首先为了方便开发，我们采用 <code>Intellij Idea</code> 作为我们开发的IDE, <a href="https://www.jetbrains.com/idea/download" rel="external nofollow noopener noreferrer" target="_blank"> 可以点此下载
</a> 。<br>安装过程比较简单我就不在此赘述了，下面我们讲解下如何设置，让你能够搭建好可以运行的插件系统。</p>
<p>打开 <code>Intellij Idea</code> ，然后选择新建项目，然后按照下图操作：</p>
<p><img src="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-18%20%E4%B8%8B%E5%8D%8811.58.59.png" alt="设置项目
"></p>
<p>然后选择Next ，然后输入你的项目名称，然后选择Finish，最后你的项目结构将如下图所示：</p>
<p><img src="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8A%E5%8D%8812.08.24.png" alt="项目结构
"></p>
<p>我们根据当前的图来简介下 <code>Intellij Idea</code> 插件开发项目的目录结构。</p>
<ul>
<li><p><code>src</code> 目录，用于存储我们编写插件的源码 </p>
</li>
<li><p><code>resources</code> 目录， 用于存储我们所需的资源文件。其中比较重要的是在 <code>META-INF</code> 文件下的 <code>plugin.xml</code> ，它是插件的配置文件，用于配置插件的各种属性各种依赖，以及注册后续将接触到的 <code>Action</code> 、 <code>Inspection</code> 等，所以此文件很重要！！! </p>
</li>
</ul>
<p>通过上面的几个简单的步骤就可以搭建完成我们的开发环境了，下面我们编写个简单的例子来熟悉下如何进行插件的开发。</p>
<hr>
<h2 id="入门操作"><a href="#入门操作" class="headerlink" title="入门操作"></a><strong>入门操作</strong></h2><h3 id="action-是什么？"><a href="#action-是什么？" class="headerlink" title="action 是什么？"></a><strong>action 是什么？</strong></h3><p>如果我上来就开始写代码你可能处于懵逼状态，好，我们先讲解下定义。<br>定义：用于描述一个动作、行为，可以通过快捷键、点选的方式进行触发。</p>
<p>下面我们将讲解两种方式去创建 <code>Action</code> ：</p>
<hr>
<h3 id="借助IDE创建Action"><a href="#借助IDE创建Action" class="headerlink" title="借助IDE创建Action"></a><strong>借助IDE创建Action</strong></h3><p>按照如下步骤进行操作：</p>
<ol>
<li>在Src目录下创建你的包，用于存储代码 </li>
<li>选择你创建的包然后点击右键- &gt;New </li>
<li>然后选择最下方的Plugin Devkit-&gt;Action </li>
</ol>
<p>参考下图：</p>
<p><img src="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8A%E5%8D%8812.29.13.png" alt="项目结构
"></p>
<p>然后需要设置Action的各个属性，可以参考下图：</p>
<p><img src="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8B%E5%8D%8811.16.32.png" alt="项目结构
"></p>
<p>然后点击下一步，你就会发现你的对应包下面就有你设置好的Action的类了。你是否好奇IDE究竟为我们做了什么？还记得说过的比较重要的那个配置文件吗？打开看看吧，你的设置是不是都在里面？是不是恍然大悟了！</p>
<p>下面介绍的创建 <code>Action</code> 的方法就是依照此原理进行的。</p>
<hr>
<h3 id="手动创建Action"><a href="#手动创建Action" class="headerlink" title="手动创建Action"></a><strong>手动创建Action</strong></h3><p>按照如下步骤进行操作：</p>
<ol>
<li>在Src目录下创建你的包，用于存储代码 </li>
<li>选择你创建的包然后点击右键- &gt;New </li>
<li>然后选择Java Class,设置好你的Action名称点击完成 </li>
</ol>
<p>将你的类继承 <code>AnAction</code> ，然后重写 <code>actionPerformed()</code> 方法，如下图所示：</p>
<p><img src="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8B%E5%8D%8811.22.28.png" alt="项目结构
"></p>
<p>我们还要配置一下 <code>plugin.xml</code> ，将你的 <code>Action</code> 注册进去。<br>配置内容，如下图：</p>
<p><img src="http://ozbc8g1sr.bkt.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-12-19%20%E4%B8%8B%E5%8D%8811.24.23.png" alt="项目结构
"></p>
<p>配置的内容参数的含义可以参考IDE生成 <code>Action</code> 时的讲解，都是对应的。</p>
<hr>
<h3 id="讲解Action"><a href="#讲解Action" class="headerlink" title="讲解Action"></a><strong>讲解Action</strong></h3><p>这个类中比较重要的有两个方法：</p>
<ul>
<li><code>actionPerformed(AnActionEvent e)</code> : 当用户点击IDE中对应Action的图标时会触发此方法，也就是说每选中一次触发一次。 </li>
<li><code>update(AnActionEvent e)</code> ：当IDE中需要展示你的Action图标的时候就会触发一次，当点击时也会触发且在 <code>actionPerformed(AnActionEvent e)</code> 之前触发。 </li>
</ul>
<hr>
<h3 id="实现个小功能"><a href="#实现个小功能" class="headerlink" title="实现个小功能"></a><strong>实现个小功能</strong></h3><p>通过上面的介绍我们对 <code>Action</code> 大致有了一些了解，下面我们来实现一些功能，来更好的学习印证一下。</p>
<p>这个例子应该是很普遍了，这个应该是官网的例子，就以此讲解吧，具体实现就是当点击你对应的 <code>Action</code> 的时候，弹出一个弹窗，下面我们看下如何实现。</p>
<p>其实代码很简单，我们刚讲解了 <code>Action</code> 比较重要的就那两个方法，根据需求我们知道 <code>actionPerformed(AnActionEvent
e)</code> 就可以满足效果，下面我们来编写代码。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@Override</span><br><span class="line">  public void actionPerformed(AnActionEvent e) &#123;</span><br><span class="line">      Messages.showMessageDialog(&quot;这个是我的测试弹窗！&quot;, &quot;TestTile&quot;, Messages.getWarningIcon());</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<p>可以看到代码确实很简单，然后我们点击运行即可， <code>IDE</code> 会自动打开新的 <code>IDE</code> 进程，如果没有直接打开对应的 <code>IDE</code><br>，你需要手动选择打开的 <code>Project</code> 即可。需要注意的是， <code>Intellij Idea</code> 中使用的 <code>Ui</code> 相关的都是基于 <code>java</code> 的，所以如果想高度定制，需要一些 <code>java ui</code> 的基础。</p>
<p>好，我们验证下学习成果，点击自动打开的 <code>IDE</code> ，上方选择 <code>help</code> ，查看最下方是不是有你命名的 <code>action</code><br>的名字，然后点击，是否出现弹窗，出现则成功。</p>
<p>如果在 <code>help</code> 下没看到你的 <code>action</code> 名字，请按照如下修改 <code>plugin.xml</code> 中的对应代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;add-to-group group-id=&quot;HelpMenu&quot; anchor=&quot;last&quot;/&gt;</span><br></pre></td></tr></table></figure>
<p>然后，重新运行即可~</p>
<p>此时重新进行点击查看应该就可以看到对应的效果了。</p>
<p>注意：如果有其他情况还请下方留言。</p>
<hr>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>至此已经基本了解了 <code>Intellij Idea</code> 的插件开发，是不是感觉还比较简单？后续会有更多更复杂的内容，敬请期待~</p>
<p>学完了内容后，多回顾多思考，继续 <a href="http://blog.csdn.net/guohaiyang1992/article/details/78838307" rel="external nofollow noopener noreferrer" target="_blank"> 后续内容
</a> 。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/intellij-idea/" <i="" class="fa fa-tag"> intellij idea</a>
          
            <a href="/tags/插件/" <i="" class="fa fa-tag"> 插件</a>
          
            <a href="/tags/android-studio/" <i="" class="fa fa-tag"> android-studio</a>
          
            <a href="/tags/plugin/" <i="" class="fa fa-tag"> plugin</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/post/d4acd4c8.html" rel="next" title="【Intellij Idea 插件】系列目录">
                <i class="fa fa-chevron-left"></i> 【Intellij Idea 插件】系列目录
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zMjczNS85Mjk2"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image" src="http://avatar.csdn.net/E/A/A/1_guohaiyang1992.jpg" alt="guohaiyang">
          <p class="site-author-name" itemprop="name">guohaiyang</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
           
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">31</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">71</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


        <!--外链播放器-->
        <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="330" height="86" src="//music.163.com/outchain/player?type=2&id=504575633&auto=0&height=66"></iframe>

      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#简介"><span class="nav-number">1.</span> <span class="nav-text">简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#基础知识"><span class="nav-number">2.</span> <span class="nav-text">基础知识</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#环境搭建"><span class="nav-number">2.1.</span> <span class="nav-text">环境搭建</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#入门操作"><span class="nav-number">3.</span> <span class="nav-text">入门操作</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#action-是什么？"><span class="nav-number">3.1.</span> <span class="nav-text">action 是什么？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#借助IDE创建Action"><span class="nav-number">3.2.</span> <span class="nav-text">借助IDE创建Action</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#手动创建Action"><span class="nav-number">3.3.</span> <span class="nav-text">手动创建Action</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#讲解Action"><span class="nav-number">3.4.</span> <span class="nav-text">讲解Action</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实现个小功能"><span class="nav-number">3.5.</span> <span class="nav-text">实现个小功能</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">4.</span> <span class="nav-text">总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">guohaiyang</span>
</div>
<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<!--<div class="powered-by"> -->
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  您是本站的第<span id="busuanzi_value_site_uv"></span>个访客，欢迎您的到来
</span>
<!--</div>-->

<!--屏蔽下方提示-->
<!--<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div> -->


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "db.json";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("h8Ih0Dm3ikBRV6HNGyvsiu8C-gzGzoHsz", "LWjl3Esuf1ArMkWbwcPbjGqV");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

  

</body>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
</html>

